import Vue from "vue";
import Vuex from "vuex";
import {
  Message
} from 'element-ui';
import {
  transToUpperCase
} from '@/tools/helper.js'

// import students from "./modules/students";
// import teachers from "./modules/teachers";
// 全局广播
import states from "./state.js";
import Api from '@/api/index.js';
// import loginApi from "@/api/login.js";
// import Api from "@/api/common.js";
import types from "@/constants/types";
import questionType from "@/constants/questionType";
import router from '@/router/index.js';

Vue.use(Vuex);

const debug = process.env.NODE_ENV !== "production";

const defineStore = new Vuex.Store({
  modules: {
    // students,
    // teachers
  },
  state: states.rootState,
  getters: {
    userInfo(state, getters, rootState) {
      return state.userInfo;
    },
    dynamicTags(state, getters, rootState) {
      return state.dynamicTags;
    },

  },
  mutations: {
    [types.USERINFO](state, value) {
      state.userInfo = value;
      state.accessToken = value.accessToken;
      sessionStorage.setItem('userInfo', JSON.stringify(value));
      sessionStorage.setItem('accessToken', value.accessToken)
      console.log(value)
      // if (value.Type == 1) {//学生登录IM
      // this.dispatch("onWebIMLogin", String(value.Id))
      // }

    },
    [types.DYNAMICTAGS](state, value) {
      state.dynamicTags = value;
    },
    [types.LOGINOUT](state, value) { //退出登陆
      state.userInfo = {};
      sessionStorage.removeItem("state");
      sessionStorage.removeItem("AccessToken");
      sessionStorage.removeItem("userInfo");
      // sessionStorage.removeItem("loginflag");
      router.push("/");
    },
  },
  actions: {
    // [types.AUTHENTICATION](context, args) {
    //     Api.GetPersonalDetails(args).then(res => {
    //         if (res) {
    //             // console.log("认证", res);
    //             // context.commit(types.AUTHENTICATION, res.data);
    //             context.commit(types.PERSONALDETAILS, res.data);
    //             //以下无用
    //             // console.log(JSON.parse(sessionStorage.getItem("personalDetails")))
    //             // if(sessionStorage.getItem("personalDetails")){
    //             //   let personal = JSON.parse(sessionStorage.getItem("personalDetails"));
    //             //   console.log(personal)
    //             //   if(personal.userType==0){
    //             //     sessionStorage.setItem("userType",2)
    //             //   }else{
    //             //     sessionStorage.setItem("userType",personal.userType)
    //             //   }
    //             // }
    //         }
    //     }).catch(err => {
    //         console.log('err', err);
    //     })
    // },
  },
  strict: debug
});

export default defineStore;
